﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WF_Business;
using WF_DataAccess;
using ExtBusiness;
using System.Net;
using ExtBusiness.Common;
using ExtBusiness.Interface;
using ExtBusiness.FlowOperation;
using ChBusiness;
using ChBusiness.Common;

public partial class office_OnlineReturn : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["serialiid"] != null)
            {
                BindMessage();
            }
            else
            {
                BindInfo();
            }
        }
    }

    /// <summary>
    /// 绑定补正内容
    /// </summary>
    /// <!--addby zhongjian 20100628-->
    protected void BindMessage()
    {
        string strIID = Request["serialiid"];//受理编号
        ClsSubmitInfo clsSubmit = new ClsSubmitInfo();
        txtRemark.Text = clsSubmit.GetFieldFromInsExt(strIID, "stop_remark");
        hidStore.Value = "补正补齐详细信息";
        txtRemark.ReadOnly = true;
        btnClose.Value = "关闭";
    }

    /// <summary>
    /// 受理业务初始化值
    /// </summary>
    protected void BindInfo()
    {
        String strBigFlowName = Request["FlowName"];//流程名称
        string strType = Request["childType"];//流程子类名称
        switch (strBigFlowName)
        {
            case "国家涉密基础测绘成果使用申报":// 
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐(涉密成果使用申报)";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理(涉密成果使用申报)";
                }
                break;
            case "永久性测量标志拆迁审批":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐(测量标志拆迁)";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理(测量标志拆迁)";
                }
                break;
            case "对外提供基础测绘成果":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐（对外提供测绘成果）";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理（对外提供测绘成果）";
                }
                break;
            case "外国来华测绘申请":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐（外国来华测绘）";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理（外国来华测绘）";
                }
                break;
            case "地图审核":
            case "地图审核(即送即审)":
            case "地图审核(5日协审)":
            case "地图审核(7日)":
            case "地图审核(20日)":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐(地图审核)";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理(地图审核)";
                }
                break;
            case "建立相对独立的平面坐标系统":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐（建立平面坐标）";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理（建立平面坐标）";
                }
                break;
            case "采用国际坐标系":
                if (strType == "1")
                {
                    hidStore.Value = "补正补齐（采用国际坐标系）";
                }
                else if (strType == "2")
                {
                    hidStore.Value = "不予受理（采用国际坐标系）";
                }
                break;
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtRemark.Text))
        {
            if (Request["iid"] != null)
            {
                NewTask();
            }
        }
        else
        {
            Common.WindowAppear.WriteAlert(this.Page, "请输入原因");
        }
    }

    #region 在线申报业务受理
    /// <summary>
    /// 在线申报业务受理
    /// </summary>
    /// <!--addby zhongjian 20091021-->
    public void NewTask()
    {
        //创建流程实例（对应在com.antu.neto.impl命名空间下）
        WorkFlow work = new WorkFlow();
        string iid = "", wiid = "", errmsg = "";
        String strSql = string.Empty;
        String strWid = "";
        string strChildFlowName = "";
        String strUserName = Request["UserName"]; //申请单位名称
        String strBigFlowName = Request["FlowName"];//流程名称
        string strType = Request["childType"];//子流程名称
        String strAppid = Request["iid"];
        String strWorkflow_Deffine = (String)Session["Workflow_Deffine"];
        
        bool bSuccess = false;
        string strStepName = "打印通知";
        string strCtlId=string.Empty;
        string strStatus = string.Empty; ;//流程状态
        //附件地址目录表
        string strAttPath = "/";

        switch (strBigFlowName)
        {
            case "国家涉密基础测绘成果使用申报":// 
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐(涉密成果使用申报)";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理(涉密成果使用申报)";
                }
                strAttPath = "扫描资料/申请资料/";
                break;
            case "永久性测量标志拆迁审批":
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐(测量标志拆迁)";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理(测量标志拆迁)";
                }
                strAttPath = "电子附件/";
                break;
            case "对外提供基础测绘成果":
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐（对外提供测绘成果）";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理（对外提供测绘成果）";
                }
                break;
            case "外国来华测绘申请":
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐（外国来华测绘）";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理（外国来华测绘）";
                }
                break;
            case "地图审核":
            case "地图审核(即送即审)":
            case "地图审核(5日协审)":
            case "地图审核(7日)":
            case "地图审核(20日)":
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐(地图审核)";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理(地图审核)";
                }
                strAttPath = "扫描资料/申请资料/";
                break;
            case "建立相对独立的平面坐标系统":
                if (strType == "1")
                {
                    strChildFlowName = "补正补齐（建立平面坐标）";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理（建立平面坐标）";
                }
                break;
            case "采用国际坐标系":
                 if (strType == "1")
                {
                    strChildFlowName = "补正补齐（采用国际坐标系）";
                }
                else if (strType == "2")
                {
                    strChildFlowName = "不予受理（采用国际坐标系）";
                }
                break;
        }
        if (strType == "1")
            strStatus = "-1";
        else if (strType == "2")
            strStatus = "-3";

        //获取流程id
        WorkFlowPubSettting wfpsTemp = new WorkFlowPubSettting();
        strWid = wfpsTemp.GetWorkWid(strChildFlowName);

        IDataAccess dataAccess = SysParams.OAConnection(true);
        try
        {
            //首先获取ctlid
            strSql = string.Format("select ctlid from st_step t where wid='{0}' and sname='{1}'", strWid,strStepName);
            strCtlId = dataAccess.GetValue(strSql);

            //创建流程
            if (true == work.NewInstance(strWid, UserId, strUserName, ref iid, ref wiid, ref errmsg, ref dataAccess))
            {
                string strCqxk = string.Empty;

                //插入工作流实例的扩展信息
                //--添加业务状态标识:status (0:已受理;2:已办结;-1:返回补证;-2:驳回中止;-3:不予受理;-4:审批不通过)
                strSql = string.Format(@"insert into xt_instance_ext(iid,申请单位,联系人,关联ID,status,stop_remark,SUBMITTIME) values({0},'{1}','{2}','{3}','{4}','{5}',(select edittime from xt_submit_info where iid = '{3}'))", iid, strUserName, UserName, strAppid, strStatus, txtRemark.Text.Trim());
                dataAccess.RunSql(strSql);

                //更新申报状态位
                strSql = string.Format("update xt_submit_info set submitflag='{2}',remark='{1}',edittime=sysdate where iid='{0}'", iid, txtRemark.Text.Trim(), strStatus);
                dataAccess.RunSql(strSql);

                //分流程类型来添加表单数据 addby zhongjian 20100311
                OracleSystemOperation osoTemp = new OracleSystemOperation();
                switch (strBigFlowName)
                {
                    case "国家涉密基础测绘成果使用申报"://将外网申报信息id(strAppid)和内网审批系统中刚刚生成的iid做好对应关系
                        //strSql = string.Format(@"update UT_测绘成果使用申请表 set appid='{0}' where iid='{1}'", iid, strAppid);
                        //dataAccess.RunSql(strSql);

                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_测绘成果使用申请表", dataAccess);
                        break;
                    case "永久性测量标志拆迁审批":
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_测量标志拆迁申请表", dataAccess);

                        break;
                    case "地图审核(即送即审)":
                    case "地图审核(5日协审)":
                    case "地图审核(7日)":
                    case "地图审核(20日)":
                    case "地图审核":
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_国家测绘局地图审核申请表", dataAccess);
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_地图审核受理通知书", dataAccess);
                        break;
                    case "对外提供基础测绘成果":
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_DWTGSMCG_SQB", dataAccess);
                        break;
                    case "外国来华测绘申请":
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_WGLHCH_SQB", dataAccess);
                        break;
                    case "建立相对独立的平面坐标系统":
                        osoTemp.GetNewTaskSql(iid, strAppid, "UT_PMXT_QKB", dataAccess);
                        break;
                    case "采用国际坐标系":
                        break;
                }

                switch (strChildFlowName)//根据子类名称的逻辑
                {
                    case "不予受理(地图审核)":
                        strSql = string.Format(@"insert into UT_地图审核不予受理通知书
  (iid,单位名称, 送审内容,收件日期,不予受理理由) select {0},单位名称, 图名,收件日期,'{2}' from ut_国家测绘局地图审核申请表 t where iid = '{1}'", iid, strAppid,txtRemark.Text);
                        dataAccess.RunSql(strSql);
                        break;
                    case "补正补齐(地图审核)":
                        strSql = string.Format(@"insert into UT_地图审核补正通知书 
  (iid,单位名称, 送审内容,收件日期,补正内容) select {0},单位名称, 图名,收件日期,'{2}' from ut_国家测绘局地图审核申请表 t where iid = '{1}'", iid, strAppid,txtRemark.Text);
                        dataAccess.RunSql(strSql);
                        break;
                }

                ClsSubmitInfo clsSubmit = new ClsSubmitInfo();
                clsSubmit.SetSubmitStatus(strAppid, strStatus, txtRemark.Text.Trim());

                //string strRemark = "";
                //if (strStatus == "-1")//补正补齐
                //{
                //    //操作描述
                //    strRemark = "退回补正:申请编号为: " + strAppid + " 补正补齐受理编号为: " + iid + " 的案件;流程类型为:" + strChildFlowName + "";
                //}
                //else if (strStatus == "-3")//不予受理
                //{
                //    //操作描述
                //    strRemark = "不予受理:申请编号为: " + strAppid + " 不予受理受理编号为: " + iid + " 的案件;流程类型为:" + strChildFlowName + "";
                //}

                ////添加操作日志
                //string myIP = Common.IPOperation.GetIpAddress();
                //SystemLogs.AddSystemLogs(UserName, "add", strRemark, "", myIP);

                //提交
                dataAccess.Close(true);
                bSuccess = true;

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", string.Format(" <script> alert('{0}'); </script> ", errmsg));
            }
        }
        catch
        {
            dataAccess.Close(false);
            throw;
        }

        if (bSuccess)
        {
            //调用父页面返回方法,返回在线申报受理页面 addby zhongjian 20100324           
            //进入业务处理页面,并关闭本页
            string strScript = string.Format(@"<script>window.opener.goReturn();OpernWorkItem('{0}',{1},'{2}');</script>", wiid, iid, strCtlId);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "closeWin", strScript);
        }
    } 
    #endregion
}
